package com.itheima.controller;

import com.itheima.domain.EmpQueryParam;
import com.itheima.domain.PageResult;
import com.itheima.domain.Result;
import com.itheima.domain.pojo.Emp;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

//@RequestMapping("/emps")
@RestController
@Slf4j
public class EmpController {
    @Autowired
  private EmpService empService;

//    @GetMapping
//    public Result page(@RequestParam(defaultValue = "1")Integer page,
//                       @RequestParam( defaultValue = "10") Integer pageSize,
//                       String name,
//                       Integer gender,
//                       @DateTimeFormat( pattern = "yyyy-MM-dd")LocalDate begin,
//                       @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end) {
//        log.info("分页查询，参数：{},{},{},{},{},{}",page,pageSize,name,gender,begin,end);
//         PageResult<Emp>pageResult= empService.page(page, pageSize, name, gender, begin, end);
//        return Result.success(pageResult);

    @GetMapping("/emps")
            //分页查询
    public Result page(EmpQueryParam empQueryParam) {
        log.info("分页查询:{}",empQueryParam);
        PageResult pageResult= empService.page(empQueryParam);
        return Result.success(pageResult);
    }
    //添加员工
    @PostMapping("/emps")
    public  Result save(@RequestBody Emp emp){
        log.info("保存员工");
        empService.save(emp);
        return Result.success();

    }

    @DeleteMapping("/emps")
    public  Result delete(@RequestParam List<Integer> ids){
        log.info("删除员工");
        empService.delete(ids);
        return Result.success();
    }

//对员工进行修改操作，获取员工信息回显，删除后添加
    @GetMapping("/emps/{id}")
    public  Result get(@PathVariable Integer id){
      Emp emp=  empService.get(id);
      return Result.success(emp);
    }
    @PutMapping("/emps")
    public  Result  update(@RequestBody Emp emp){
        log.info("修改员工信息");
        empService.update(emp);
        return Result.success();
    }
//查询全部员工信息作业1
    @GetMapping("/emps/list")
    public Result lists(){
        log.info("查询全部员工信息");
        List<Emp> empList= empService.lists();
        return Result.success(empList);
    }


    //作业2
}
